<?php
session_start();

include "webmaster_connect.php";

$page_permission = 2;

include "webmaster_check_login.php";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
body {
	background-image: url(../images/wood.jpg);
	background-repeat: repeat-x;
	margin: 0px;
	background-position: left top;
	background-attachment: fixed;
	background-color: #000000;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
}
</style>
<link href="../css/webmaster_guest_alerts.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="page_container">

<?php 

include "../admin_files/webmaster_header.php";
include "../admin_files/webmaster_navigation.php" 

?>

<div id="content_container">


<h1>Guest alerts:</h1>

<form id="date_filter" action="webmaster_customer_searches.php" method="post" name="date_filter">

<?php $today = date("Y/m/d"); ?>

<label> Show: 
<select name="search_date">
<option value="<?php echo $today ?>">Todays</option>
<option value="All">All</option>
</select>
</label>

<input name="refresh_messages" type="submit" value="Refresh" />

<table width="970px" border="0" cellpadding="3">

<tr>
    <th class="header" scope="col">Date</th>
    <th class="header" scope="col">Time</th>
    <th class="header" scope="col">Searched</th>
    <th class="header" scope="col">Results</th>
    <th class="header" scope="col">IP Address</th>
  </tr>

<?php 
 
$selected_date = $_POST['search_date'];
 
$query = "SELECT * FROM search_history";

if(!isset($_POST['search_date']))
{
	$query .= " WHERE search_date = '$today'";
} else
{
	if($selected_date != "All"){$query .= " WHERE search_date = '$selected_date'";}	
}

$query .= " ORDER BY search_id DESC";

$result = mysql_query($query);

$row_cnt = mysql_num_rows($result); //Number of results

while($row = mysql_fetch_array($result))
{
	
	$search_date = $row['search_date'];
	$search_date = date("d/m/Y", strtotime($search_date));
	
echo '

  <tr id="'.$row['search_id'].'">
	<th>'.$search_date.'</th>
	<th>'.$row['search_time'].'</th>
	<th>'.$row['search_string'].'</th>
	<th>'.$row['number_results'].'</th>
    <th>'.$row['ip_address'].'</th>
  </tr>

';
	
}


?>

</table>

<label><b>Results:</b> <?php echo $row_cnt ?></label>

<?php
/////////////////////////
//TESTING - Display query
/////////////////////////

//echo $query 

/////////////
//END Testing
/////////////

?>

</div>
<!--login_container-->

</div> 
<!--page_container-->

</body>
</html>

